using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using Htse.Blue.Logic;
using Htse.Blue.Models;
using Htse.Blue.Logic.Validation;

namespace Htse.Blue.Controllers
{
	[HandleError(Order = 0)]
	public class CityController : Controller
	{
		private ICityService _cityService;

		public CityController()
		{
			_cityService = new CityService(new ModelStateWrapper<City>(ModelState));
		}

		public CityController(ICityService cityService)
		{
			_cityService = cityService;
		}

		[Authorize]
		public JsonResult GetCitiesNames()
		{
			var cities = from city in _cityService.GetAll()
							 orderby city.Name
							 select new { Text = city.Name, Value = city.Id };


			return Json(cities, JsonRequestBehavior.AllowGet);
		}
	}
}
